using UnityEngine;
using System.Collections;
using System.Collections.Generic;


public class MenuModel : HUDElement {

    public string fileName;
    protected List<Transform> _listTexts = new List<Transform>();
    protected List<Transform> _listTextures = new List<Transform>();

    void Awake()
    {
        //Place Anchors
        InterfaceCreator.SetParameters(this.camera, this.transform);

        DeserializeMenu(Const.PATH_XML + fileName);
    }

    public override void OnRelease(object o)
    {

        SoundManager.Instance.PlayFX("clickButton");

    }

    void DeserializeMenu(string filePath)
    {

        TextAsset txt = (TextAsset)Resources.Load(filePath);

        XMLInStream stream = new XMLInStream(txt.text);


        //Buttons
        stream.List("button", delegate(XMLInStream stream2)
        {
            Transform button = InterfaceCreator.DeserializeButton(stream2, this.transform);
            AddButton(button.GetComponent<HUDButton>());
        });

        //Text
        stream.List("text", delegate(XMLInStream stream2)
        {
            _listTexts.Add(InterfaceCreator.DeserializeText(stream2, this.transform));
        });

        //Texture
        stream.List("texture", delegate(XMLInStream stream2)
        {
            _listTextures.Add(InterfaceCreator.DeserializeTexture(stream2, this.transform));
        });

    }
}
